package com.fz.com.fz.service;
import com.fz.com.fz.util.MybatisUtil;
import com.fz.entity.Book;
import com.fz.mapper.BookMapper;
import org.apache.ibatis.session.SqlSession;
import java.util.List;
/**
 * Created by David on 2017-06-30.
 */
public class BookServiceImpl implements BookService {
    private BookMapper bookdao;
    private SqlSession session;

    public BookServiceImpl(){
        this.session = new MybatisUtil().getSession();
        this.bookdao = this.session.getMapper(BookMapper.class);
    }

    @Override
    public List<Book> queryAll() {
        List<Book> bk = this.bookdao.queryAll();
        this.session.commit();
        return bk;
    }

    @Override
    public int deleteById(int id) {
       int n = this.bookdao.deleteById(id);
       this.session.commit();
       return n;
    }

    @Override
    public int add(Book book) {
        int n = this.bookdao.add(book);
        this.session.commit();
        return n;
    }
}
